<html>
<head>
<script type="text/javascript">
	var path;
	var ws;
	function init() {
		console.log("init");
		if (ws != null) {
			ws.close();
			ws = null;
		}
		path = document.msgform.path.value;
		console.log("path:" + path);
		var div = document.getElementById("msg");
		div.innerText = "path:" + path + "\n" + div.innerText;
		ws = new WebSocket("ws://localhost:23456" + path);

		ws.onopen = function() {
			div.innerText = "opened\n" + div.innerText;
		};
		ws.onmessage = function(e) {
			div.innerText = "msg:" + e.data + "\n" + div.innerText;
		};
		ws.onclose = function(e) {
			div.innerText = "closed\n" + div.innerText;
		};
		console.log("init");
		div.innerText = "init\n" + div.innerText;
	};
	function send() {
		console.log("send");
		var m = document.msgform.message.value;

		console.log("send:" + m);

		ws.send(m);
		return false;
	};
</script>
<body onLoad="init();">
	<form name="msgform" action="#" onsubmit="return send();">
		<select onchange="init()" name="path">
			<option value="/sendRecvText">/sendRecvText</option>
		</select>
		<input type="text" name="message" size="80" value="">
		<input type="file" name="file">
		<input type="submit" value="send">
	</form>
	<div id="msg"></div>
</body>
</html>